package com.apestech.framework.util.modul;

import com.alibaba.druid.pool.DruidDataSource;
import com.apestech.framework.db.SqlDataSource;

import java.sql.SQLException;

/**
 * @author hup
 * @create 2018-08-30-17:04
 */
public class DBInfo {

    private String dbName=null;
    private SqlDataSource ds=null;

    public DBInfo(Object datasource, String dbName) throws SQLException {
        if(datasource instanceof SqlDataSource){
            this.ds= (SqlDataSource) datasource;
        } else {
            this.ds=new SqlDataSource(datasource);
        }
        if(dbName==null){
            this.dbName=ds.getUsername();
        } else {
            this.dbName=dbName;
        }
    }

    public String getDbType() {
        return ds.getDbType();
    }

    public String getSchema() {
        return ds.getSchema();
    }

    public String getDbUser() {
        return ds.getUsername();
    }

    public String getDbName() {
        return dbName;
    }

    public String getId() {
        return ds.getId();
    }

    public SqlDataSource getDs() {
        return ds;
    }

    public DruidDataSource getDataSource(){
        return ds.getDruidDataSource();
    }

}
